<template>
    <div v-if="setModel" class="model">
            <div class="box setHeight">
               <p class="titP">设置</p>
               <div class="claList">
                   <ul>
                       <li class="claM">
                           <span class="claSpan">结算方式：</span>
                           <select class="selType" v-model="closeType">
                               <option :value="1">支付宝</option>
                               <option :value="2">微信</option>
                           </select>
                       </li>
                       <li class="claM">
                           <span class="claSpan">账号：</span>
                           <input v-model.trim="closeID" class="claInput" type="text">
                       </li>
                       <li class="claM">
                           <span class="claSpan">所有人：</span>
                           <input class="claInput" v-model.trim="IDholder" type="text">
                       </li>
                   </ul>
               </div>
               <div class="twoBtn">
                   <div class="confirm" @click="save">确定</div>
                   <div class="cancel" @click="hide">取消</div>
               </div>
            </div>
        </div>
</template>
<script>
export default {
    data() {
        return {
            closeType: 1,
            closeID: '',
            IDholder: '',
            dataId:'',
            setData: {}
        }
    },
     props:{
        setModel:{
            type:Boolean,
            default:true
        }
    },
    mounted() {
        this.getSetData()
    },
    methods: {
        hide () {
            this.$emit('hide')
        },
        save () {
            if(!this.checkSet()){
                return
            }
            this.alterSetData()
        },
        // 获取账户设置
        getSetData () {
            var params = {
                SchoolId : this.$parent.schoolId,
                GradeId: this.$parent.gradeId,
                ClassId: this.$parent.classId,
                PageNum: 1,
                PageSize: 1
            }
            this.$store.dispatch('classFee/GetStatistics', params).then( res => {
                this.setData = res.items[0]
                this.closeType = this.setData.cashType
                this.closeID = this.setData.account
                this.IDholder = this.setData.accountOwner
                this.dataId = this.setData.id
            })
        },
        // 修改账户设置 PutClassFareAccountManage
        alterSetData () {
           var params = {
                account : this.closeID,
                accountOwner: this.IDholder,
                cashType: this.closeType,
                id: this.dataId,
                settleStateCycleType: 1
            }
            this.$store.dispatch('classFee/PutClassFareAccountManage', params).then( res => {
                this.$vux.toast.text('修改成功', 'middle')
                this.$emit('hide')
            }).catch(res => {
                 this.$emit('hide')
            })
        },
        checkSet(){
           if(!this.closeID || this.closeID.length > 20){
               this.$vux.toast.text('账号不能为空且字数不能超过20', 'middle')
               return false
           }
           if(!this.IDholder || this.closeID.length > 20){
               this.$vux.toast.text('所有人不能为空且字数不能超过20', 'middle')
               return false
           }
           return true
       }
    },
}
</script>
<style src="./css/classFee.css" scoped>

</style>